package file;

import java.io.File;
import java.io.FileFilter;

public class LitsFilesDemo2 {
    public static void main(String[] args) {
        //获取当前目录下名字中含有字母"s"的所有子项

        File dir = new File(".");
        if (dir.isDirectory()){
            FileFilter filter = new FileFilter() {
                public boolean accept(File file) {
                    String name = file.getName();
                    return name.contains("s");
                }
            };
            File[] subs = dir.listFiles(filter);
            System.out.println(subs.length);
            for (int i = 0; i < subs.length; i++) {
                File sub = subs[i];
                System.out.println(sub.getName());
            }
        }
    }
}
